package cn.dazhou.contextholder

import android.app.Application
import java.lang.RuntimeException

/**
 * 此类用于长久保存一个Application的实例，以方便在需要的时候调用getContext()来获取。
 * 注：必须在Application中调用ContextHolder.init(application)来进行初始化
 */
object ContextHolder {

    private var application: Application? = null

    fun init(application: Application) {
        this.application = application
    }

    @Suppress("unused")
    fun getContext(): Application {
        return application ?: throw RuntimeException("必须在Application中调用ContextHolder.init(application)函数")
    }
}